var utils = require("../../../utils/util.js");
var app = getApp();
Page({
  data: {
    arr:[], //放置返回数据的数组  
    pageIndex: 1,   // 设置加载的第几次，默认是第一次  
    pageSize: 10,      //返回数据的个数  
    hasData:true,  //“没有数据”的变量，默认false，隐藏   
    projectId:1  
  },
  onLoad:function(){
    this.ajax();
  },
  onPullDownRefresh:function(){
    this.setData({
      pageIndex:1,
      hasData:true
    });
    this.ajax();
    wx.stopPullDownRefresh();
  },
  onReachBottom: function () {
    if (this.data.hasData) {
      this.ajax();
    }
  },
  ajax: function (e) {
    let that=this;
    //wx.showLoading();
    wx.request({
      url: utils.dominame +'/api/getMyReserveOrderList',
      data: {
        token: app.globalData.token,
        project_id: that.data.projectId,
        pageSize: that.data.pageSize,
        pageIndex: that.data.pageIndex
      },
      header: { "Content-Type": "application/x-www-form-urlencoded"},
      method:'GET',
      dataType: 'json',
      responseType: 'text',
      success: function(res) {
        console.log(res);
        if (res.data.code == 0) {
          var arrBox;
          if (that.data.pageIndex == 1) {
            arrBox = res.data.data.rows.rows;
          } else {
            arrBox = that.data.arr.concat(res.data.data.rows.rows)
          };
          if (that.data.pageSize * that.data.pageIndex < res.data.data.rows.recordCount) {
            var num = that.data.pageIndex + 1;
            that.setData({
              arr: arrBox,
              hasData: true,
              pageIndex: num
            });
          } else {
            that.setData({
              arr: arrBox,
              hasData: false
            });
          }
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          })
        }
      },
      fail: function(res) {},
      complete: function(res) {
        //wx.hideLoading();
      },
    })
  },
  seeResevationOrder:function(e){
    wx.navigateTo({
      url: '../myReservationOrderDetail/myReservationOrderDetail?orderno='+e.currentTarget.dataset.orderno,
    })
  },
  tabBarTap:function(e){
    this.setData({
      pageIndex:1,
      hasData:true,
      arr:[],
      projectId:e.currentTarget.dataset.controlitemid
    });
    this.ajax();
  }
})